﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="RestServiceWebClient.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/jscript" src="Scripts/jquery-1.4.1.min.js"></script>
    <script type="text/javascript">

            function GetProducts() {
            $.ajax({
                type: "GET",
                url: "http://localhost:8892/BilgeRestService.svc/GetProducts/4",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccessJson,
                error: OnErrorJson
            });
        }
        function OnSuccessJson(data, status) {
            var result = data;
            var div1 = document.getElementById('div1');
            div1.innerHTML = "";
            for (var i = 0; i < data.length; i++) {
                div1.innerHTML += data[i].ProductName + "  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  " + data[i].CategoryName + "</br>";
            }
        }
        function OnErrorJson(data, status) {
            alert("Exception");
        } 
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <input id="btnGetProducts" type="button" value="Get Products" onclick="GetProducts(5)" />
    <div id="div1">
    </div>
    </form>
</body>
</html>
